home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / EVAL.C < prev    next >
C/C++ Source or Header  |  1992-03-25  |  4KB  |  154 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: eval.c,v 3.26 92/03/24 22:34:32 woo Exp Locker: woo $";
  3. #endif
  4.  
  5. /* GNUPLOT - eval.c */
  6. /*
  7.  * Copyright (C) 1986, 1987, 1990, 1991, 1992   Thomas Williams, Colin Kelley
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software is provided "as is" without express or implied warranty.
  20.  * 
  21.  *
  22.  * AUTHORS
  23.  * 
  24.  *   Original Software:
  25.  *     Thomas Williams,  Colin Kelley.
  26.  * 
  27.  *   Gnuplot 2.0 additions:
  28.  *       Russell Lang, Dave Kotz, John Campbell.
  29.  *
  30.  *   Gnuplot 3.0 additions:
  31.  *       Gershon Elber and many others.
  32.  * 
  33.  * Send your comments or suggestions to 
  34.  *  info-gnuplot@ames.arc.nasa.gov.
  35.  * This is a mailing list; to join it send a note to 
  36.  *  info-gnuplot-request@ames.arc.nasa.gov.  
  37.  * Send bug reports to
  38.  *  bug-gnuplot@ames.arc.nasa.gov.
  39.  */
  40.  
  41. #include <stdio.h>
  42. #include "plot.h"
  43.  
  44. extern int c_token;
  45. extern struct ft_entry ft[];
  46. extern struct udvt_entry *first_udv;
  47. extern struct udft_entry *first_udf;
  48. extern struct at_type at;
  49. extern struct lexical_unit token[];
  50.  
  51. struct value *integer();
  52.  
  53.  
  54.  
  55. struct udvt_entry *
  56. add_udv(t_num)  /* find or add value and return pointer */
  57. int t_num;
  58. {
  59. register struct udvt_entry **udv_ptr = &first_udv;
  60.  
  61.     /* check if it's already in the table... */
  62.  
  63.     while (*udv_ptr) {
  64.         if (equals(t_num,(*udv_ptr)->udv_name))
  65.             return(*udv_ptr);
  66.         udv_ptr = &((*udv_ptr)->next_udv);
  67.     }
  68.  
  69.     *udv_ptr = (struct udvt_entry *)
  70.       alloc((unsigned int)sizeof(struct udvt_entry), "value");
  71.     (*udv_ptr)->next_udv = NULL;
  72.     copy_str((*udv_ptr)->udv_name,t_num);
  73.     (*udv_ptr)->udv_value.type = INT;    /* not necessary, but safe! */
  74.     (*udv_ptr)->udv_undef = TRUE;
  75.     return(*udv_ptr);
  76. }
  77.  
  78.  
  79. struct udft_entry *
  80. add_udf(t_num)  /* find or add function and return pointer */
  81. int t_num; /* index to token[] */
  82. {
  83. register struct udft_entry **udf_ptr = &first_udf;
  84.  
  85.     while (*udf_ptr) {
  86.         if (equals(t_num,(*udf_ptr)->udf_name))
  87.             return(*udf_ptr);
  88.         udf_ptr = &((*udf_ptr)->next_udf);
  89.     }
  90.      *udf_ptr = (struct udft_entry *)
  91.       alloc((unsigned int)sizeof(struct udft_entry), "function");
  92.     (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
  93.     (*udf_ptr)->definition = NULL;
  94.     (*udf_ptr)->at = NULL;
  95.     copy_str((*udf_ptr)->udf_name,t_num);
  96.     (void) integer(&((*udf_ptr)->dummy_values[0]), 0);
  97.     (void) integer(&((*udf_ptr)->dummy_values[1]), 0);
  98.     return(*udf_ptr);
  99. }
  100.  
  101.  
  102. union argument *
  103. add_action(sf_index)
  104. enum operators sf_index;        /* index of p-code function */
  105. {
  106.     if (at.a_count >= MAX_AT_LEN)
  107.         int_error("action table overflow",NO_CARET);
  108.     at.actions[at.a_count].index = sf_index;
  109.     return(&(at.actions[at.a_count++].arg));
  110. }
  111.  
  112.  
  113. int standard(t_num)  /* return standard function index or 0 */
  114. {
  115. register int i;
  116.     for (i = (int)SF_START; ft[i].f_name != NULL; i++) {
  117.         if (equals(t_num,ft[i].f_name))
  118.             return(i);
  119.     }
  120.     return(0);
  121. }
  122.  
  123.  
  124.  
  125. execute_at(at_ptr)
  126. struct at_type *at_ptr;
  127. {
  128. register int i,index,count,offset;
  129.  
  130.     count = at_ptr->a_count;
  131.     for (i = 0; i < count;) {
  132.         index = (int)at_ptr->actions[i].index;
  133.         offset = (*ft[index].func)(&(at_ptr->actions[i].arg));
  134.         if (is_jump(index))
  135.             i += offset;
  136.         else
  137.             i++;
  138.     }
  139. }
  140.  
  141. /*
  142.  
  143.  'ft' is a table containing C functions within this program. 
  144.  
  145.  An 'action_table' contains pointers to these functions and arguments to be
  146.  passed to them. 
  147.  
  148.  at_ptr is a pointer to the action table which must be executed (evaluated)
  149.  
  150.  so the iterated line exectues the function indexed by the at_ptr and 
  151.  passes the address of the argument which is pointed to by the arg_ptr 
  152.  
  153. */
  154.